package com.me.kafka.controller;

import com.me.kafka.service.ProduceKafkaMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试发送消息
 *
 * @author Wuzhiming
 */
@RestController
@RequestMapping("send-kafka-message")
@Slf4j
public class TestController {

    @Autowired
    private ProduceKafkaMessage produceKafkaMessage;

    @GetMapping("sendMessage")
    public String sendMessage(String message) {
        produceKafkaMessage.sendMessage("test", message);
        return "success";
    }
    @GetMapping("sendMessageRollback")
    public String sendMessageRollback(String message) {
        produceKafkaMessage.sendMessageRollback("test", message,success->{
            if(success!=null){
                log.info(success.getClass().toString());
                log.info("消息发送成功："+success);
            }
        },failBack->{
            log.error("消息消费失败："+failBack.getMessage());
        });
        return "success";
    }

}
